/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logic;

import java.awt.Image;
import java.awt.Toolkit;
import java.beans.PropertyVetoException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

/**
 *
 * @author TuxCompany
 */
public class This {

    public static String AlfaNum(int Lenght) {
        String uuid = UUID.randomUUID().toString();
        StringBuilder x = new StringBuilder(uuid.replace("-", ""));
        x.setLength(Lenght);
        return x.toString();
    }

    public static void hide(JFrame Frame) {
        Frame.setVisible(false);
    }

    public static void show(JFrame Frame) {
        Frame.setVisible(true);
    }

    public static void show(JInternalFrame JIP) {
        if (!JIP.isVisible()) {
            JIP.setVisible(true);
        }
        if (JIP.isIcon()) {
            try {
                JIP.setIcon(false);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(This.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static void hide(JPanel Panel) {
        Panel.setVisible(false);
    }

    public static void Maximized(JFrame Frame) {
        Frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    public static boolean Enter(java.awt.event.KeyEvent E) {
        if (E.getKeyChar() == java.awt.event.KeyEvent.VK_ENTER) {
            return true;
        }
        return false;
    }

    public static void AddInter(javax.swing.JDesktopPane JDP, javax.swing.JInternalFrame JIP) {
        try {
            JDP.add(JIP);
        } catch (java.lang.IllegalArgumentException IAE) {
        }
    }

    public static Image getIconImageFrame() {
        Image retValue = Toolkit.getDefaultToolkit().
                getImage(ClassLoader.getSystemResource("resources/notify.png"));
        return retValue;
    }

    public static Image getIconImageIFrame() {
        Image retValue = Toolkit.getDefaultToolkit().
                getImage(ClassLoader.getSystemResource("resources/gIFrame.png"));
        return retValue;
    }

    //Habilitado para 3 componentes de texto
    public static void Clean(javax.swing.JComponent c) {
        try {
            javax.swing.JTextField JT = (javax.swing.JTextField) c;
            JT.setText("");
            return;
        } catch (java.lang.ClassCastException e) {
        }
        try {
            javax.swing.JTextArea JT = (javax.swing.JTextArea) c;
            JT.setText("");
            return;
        } catch (java.lang.ClassCastException e) {
        }
        try {
            javax.swing.JTextPane JT = (javax.swing.JTextPane) c;
            JT.setText("");
            return;
        } catch (java.lang.ClassCastException e) {
        }
    }

    public static void ValidNumber(java.awt.event.KeyEvent evt) {
        if (Character.isLetter(evt.getKeyChar())) {
            evt.consume();
        }
    }
}
